<?php
   if($_GET["zid"] == ""){
	print("need zid 01 or 63");
    	exit;
    }
    if($_GET["date"] == ""){
	print("need date xxxx-xx-xx");
    	exit;
    }
    if($_GET["time"] == ""){
	$_GET["time"] = "00:00:00";
    } 
	

    $conn = mysql_connect("10.3.22.69","work@RR","Geeker4ZolZ");
    mysql_select_db("ad_stat");
  
    //print($_GET["zid"]); 
    $sql="select user_id, sum(pv_count) as pv, sum(click_count) as click, time from ad_stat_tag_hourly where adzone_id = 1000000000".$_GET["zid"]." and time between '".$_GET["date"]." ".$_GET["time"]."' and  '".$_GET["date"]." ".$_GET["time"]."' + INTERVAL 1 hour group by user_id order by user_id; ";
    //print($sql);

    $result = mysql_query($sql);

?>

adzone:<?=$_GET["zid"]?>   time:<?=$_GET["date"]." ".$_GET["time"]?>  
<p/>


分小时的总点击率分布
<table border="1">
<tr>
<td>uid</td>
<td>pv</td>
<td>click</td>
<td>ctr</td>
<td>time</td>
</tr>
<?
    $pv_list="";
    $max_y = 0;
    $i = 0;
    $pv_array=array();
    $sum_rrpv=0;
    $sum_twpv=0;
    $sum_twclick=0;
    $sum_rrclick=0;
    while( $row = mysql_fetch_array($result)) {
	print("<tr>");

	print("<td>".$row["user_id"]."</td>");    
	print("<td>".$row["pv"]."</td>");    
	print("<td>".$row["click"]."</td>");    
	$ctr = $row["click"]/$row["pv"] * 100;
	print("<td>".round($ctr,4)."%</td>");    
	print("<td>".$row["time"]."</td>");    
	print("</tr>");
	if($pv_list != ""){
		$pv_list.=",";
	}    
	//$pv_list .= round($ctr*1000,1);
    	$pv_array[$i] = $ctr;
	$i++;
        $max_y = $ctr > $max_y ? $ctr:$max_y;
    	if($row["user_id"] < 5){
		$sum_twpv+= $row["pv"];
		$sum_twclick+= $row["click"];
        }else{
		$sum_rrpv+= $row["pv"];
                $sum_rrclick+= $row["click"];
	}
    }

    for($i=0; $i < count($pv_array); $i++){
    	if($i != 0){ $pv_list .= ","; }
        $pv_list .= round($pv_array[$i]/$max_y * 100,1);
	
    }
?>
<tr>
<td>
<strong>
<?php
	//print ($pv_list);
	print ("<img src=\"https://chart.googleapis.com/chart?chs=600x300&chbh=10,4,10&cht=bvg&chxt=x,y&chxr=1,0,20&chg=10,5&chd=t:".$pv_list."\"/><br/>");
	print ("tw_pv:".$sum_twpv." tw_click:".$sum_twclick." ctr:".round($sum_twclick/$sum_twpv*100,4)."%<br/>");
	print ("rr_pv:".$sum_rrpv." rr_click:".$sum_rrclick." ctr:".round($sum_rrclick/$sum_rrpv*100,4)."%<br/>");
	$r=$sum_twclick/$sum_twpv/($sum_rrclick/$sum_rrpv)*100;
	if($r>100){
		print ("台湾比我们好的比率：<font color=green>".round($sum_twclick/$sum_twpv/($sum_rrclick/$sum_rrpv)*100,4)."%</font>");
	}else{
	
		print ("台湾比我们好的比率：<font color=red>".round($sum_twclick/$sum_twpv/($sum_rrclick/$sum_rrpv)*100,4)."%</font>");
	}
?>
</strong>
</td>
</tr>


</table>

<p/>
------------------------</br>
台湾点击率与我们的两个不同的算法的点击率的比较
<?php
    
	

    $conn = mysql_connect("10.3.22.69","work@RR","Geeker4ZolZ");
    mysql_select_db("ad_stat");
  
    print($_GET["zid"]); 
    $sql="select user_id, tag, sum(pv_count) as pv, sum(click_count) as click, time from ad_stat_tag_hourly where adzone_id = 1000000000".$_GET["zid"]." and time between '".$_GET["date"]." ".$_GET["time"]."' and  '".$_GET["date"]." ".$_GET["time"]."' + INTERVAL 1 hour group by user_id, tag order by user_id, tag;";
    //print($sql);

    $result = mysql_query($sql);
?>
<table border="1">
<tr>
<td>uid</td>
<td>tag</td>
<td>pv</td>
<td>click</td>
<td>ctr</td>
<td>time</td>
</tr>
<?
    $pv_list="";
    $max_y = 0;
    $i = 0;
    $pv_array=array();
    while( $row = mysql_fetch_array($result)) {
	print("<tr>");

	print("<td>".$row["user_id"]."</td>");    
	print("<td>".$row["tag"]."</td>");    
	print("<td>".$row["pv"]."</td>");    
	print("<td>".$row["click"]."</td>");    
	$ctr = $row["click"]/$row["pv"] * 100;
	print("<td>".round($ctr,4)."%</td>");    
	print("<td>".$row["time"]."</td>");    
	print("</tr>");
	if($pv_list != ""){
		$pv_list.=",";
	}    
	//$pv_list .= round($ctr*1000,1);
    	$pv_array[$i] = $ctr;
	$i++;
        $max_y = $ctr > $max_y ? $ctr:$max_y;
    }

    for($i=0; $i < count($pv_array); $i++){
    	if($i != 0){ $pv_list .= ","; }
        $pv_list .= round($pv_array[$i]/$max_y * 100,1);
	
    }
?>
<tr>
<td>
<?php
	//print ($pv_list);
	print ("<img src=\"https://chart.googleapis.com/chart?chs=600x300&chbh=10,4,10&cht=bvg&chxt=x,y&chxr=1,0,20&chg=10,5&chd=t:".$pv_list."\"/>");
?>
</td>
</tr>


</table>

-------------------<br/>
按天的总点击率分布比较

<?php
    
	

    $conn = mysql_connect("10.3.22.69","work@RR","Geeker4ZolZ");
    mysql_select_db("ad_stat");
  
    //print($_GET["zid"]); 
    $sql="select user_id, sum(pv_count) as pv, sum(click_count) as click, time from ad_stat_tag_hourly where adzone_id = 1000000000".$_GET["zid"]." and time like '".$_GET["date"]."%' group by user_id order by user_id; ";
    //print($sql);

    $result = mysql_query($sql);

?>

<table border="1">
<tr>
<td>uid</td>
<td>pv</td>
<td>click</td>
<td>ctr</td>
<td>time</td>
</tr>
<?
    $pv_list="";
    $max_y = 0;
    $i = 0;
    $pv_array=array();
    $sum_rrpv=0;
    $sum_twpv=0;
    $sum_twclick=0;
    $sum_rrclick=0;
    while( $row = mysql_fetch_array($result)) {
	print("<tr>");

	print("<td>".$row["user_id"]."</td>");    
	print("<td>".$row["pv"]."</td>");    
	print("<td>".$row["click"]."</td>");    
	$ctr = $row["click"]/$row["pv"] * 100;
	print("<td>".round($ctr,4)."%</td>");    
	print("<td>".$row["time"]."</td>");    
	print("</tr>");
	if($pv_list != ""){
		$pv_list.=",";
	}    
	//$pv_list .= round($ctr*1000,1);
    	$pv_array[$i] = $ctr;
	$i++;
        $max_y = $ctr > $max_y ? $ctr:$max_y;
    	if($row["user_id"] < 5){
		$sum_twpv+= $row["pv"];
		$sum_twclick+= $row["click"];
        }else{
		$sum_rrpv+= $row["pv"];
                $sum_rrclick+= $row["click"];
	}
    }

    for($i=0; $i < count($pv_array); $i++){
    	if($i != 0){ $pv_list .= ","; }
        $pv_list .= round($pv_array[$i]/$max_y * 100,1);
	
    }
?>
<tr>
<td>
<strong>
<?php
	//print ($pv_list);
	print ("<img src=\"https://chart.googleapis.com/chart?chs=600x300&chbh=10,4,10&cht=bvg&chxt=x,y&chxr=1,0,20&chg=10,5&chd=t:".$pv_list."\"/><br/>");
	print ("tw_pv:".$sum_twpv." tw_click:".$sum_twclick." ctr:".round($sum_twclick/$sum_twpv*100,4)."%<br/>");
	print ("rr_pv:".$sum_rrpv." rr_click:".$sum_rrclick." ctr:".round($sum_rrclick/$sum_rrpv*100,4)."%<br/>");
	$r=$sum_twclick/$sum_twpv/($sum_rrclick/$sum_rrpv)*100;
	if($r>100){
		print ("台湾比我们好的比率：<font color=green>".round($sum_twclick/$sum_twpv/($sum_rrclick/$sum_rrpv)*100,4)."%</font>");
	}else{
	
		print ("台湾比我们好的比率：<font color=red>".round($sum_twclick/$sum_twpv/($sum_rrclick/$sum_rrpv)*100,4)."%</font>");
	}
?>
</strong>
</td>
</tr>


</table>


